#include "message.h"
#include <iostream>

using namespace std;


/*
 * Message class constructor
 */
Message::Message() {
	first_roller = 1;
}



/*
 * Print a custom message
 */
void Message::printMessage(const char* message) {
	this->stopRoller();
	cout << message;
}

void Message::printMessage(int number) {
	this->stopRoller();
	cout << number;
}

void Message::printMessage(double number) {
	this->stopRoller();
	cout << number;
}

/*
 * Print a custom error
 */
void Message::printError(const char* message) {
	this->stopRoller();
	cerr<<message;
}



/*
 * Show welcome message
 */
void Message::showWelcome()
{
	this->stopRoller();
	cout<<"ncompress - neural network image compressor\n";
	cout<<"(c) 2006-2008 Vlad Ureche, distributed under revised BSD license\n\n";
}



/*
 * Show usage message
 */
void Message::showUsage()
{
	this->stopRoller();
	cout<<"\nusage: ncompress {c|x} <source> <destination> [OPTIONS]\n\n";
	cout<<"ARGUMENTS: c=compress\n";
	cout<<"           x=extract\n\n";
	cout<<"OPTIONS:   --color     try to compress color images (not working now)\n";
	cout<<"           --verbose   detailed information on what's happening\n\n";
	cout<<"           --sec <sec> (for compression) maximum compression time in seconds (default 60)\n";
	cout<<"           --iter <it> (for compression) maximum iterations\n";
	cout<<"           --snr <SNR> (for compression) desired SNR (Sound to Noise Ratio)\n";
	cout<<"EXAMPLE:   nncomp c party.bmp party.nn --sec 60 \n\n";
}



/*
 * Show usage message
 */
void Message::showUsageMPI()
{
	this->stopRoller();
	cout<<"\nusage: ncompress c <source> <destination> [OPTIONS]";
	cout<<"\nMPI-version\n\n";
	cout<<"ARGUMENTS: c=compress\n";
	cout<<"           extract is not supported!!!\n\n";
	cout<<"OPTIONS:   --color     try to compress color images (not working now)\n";
	cout<<"           --verbose   detailed information on what's happening\n\n";
	cout<<"           --sec <sec> (for compression) maximum compression time in seconds (default 60)\n";
	cout<<"           --iter <it> (for compression) maximum iterations\n";
	cout<<"           --snr <SNR> (for compression) desired SNR (Sound to Noise Ratio)\n";
	cout<<"EXAMPLE:   nncomp c party.bmp party.nn --sec 60 \n\n";
}




/*
 * Stop the roller: in case it is rolling, print an enter or erase it.
 */
void Message::stopRoller() {
	if (!first_roller) {
		cout<<"\b";
		first_roller=1;
	}
}


/*
 * Show roller in action
 */
void Message::showRoller() {
	const char* roller = "-/|\\";
	const int roller_max=3;

	if (!first_roller)
		cout<<"\b";
	else
		first_roller=0;
	
	cout<<roller[roller_crt++];
	if (roller_crt>roller_max)
		roller_crt=0;
}
